package com.su.ou.yang;

import java.util.ArrayList;

public class Test1 {
    public static void main(String[] args) {
        ArrayList<ArrayList<Integer>> res = new ArrayList<>();
        ArrayList<Integer> list = new ArrayList<Integer>();

        int[] nums={2,3,5};
        int k=8;
        solve(nums,k,res,list,0);
        for (int i = 0; i <res.size() ; i++) {
            System.out.println(res.get(i));
        }

    }
    public  static void solve(int[] nums,int target, ArrayList<ArrayList<Integer>> res,ArrayList<Integer> list, int start){
        if(target==0){
            res.add(new ArrayList<Integer>(list));
            return;
        }
        for (int i = start; i <nums.length ; i++) {
            if(target<nums[i]){
                continue;
            }

            list.add(nums[i]);
            solve(nums, target-nums[i],res,list,i+1);
            list.remove(list.size()-1);
        }
    }
}
